package com.example.big_event.controller;

import com.example.big_event.pojo.Result;
import com.example.big_event.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController
public class FileUploadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件的内容存储到本地磁盘
        String originalFilename=file.getOriginalFilename();

        //保证文件的名字是唯一的，从而防止文件覆盖
        String filename= UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));


       String url= AliOssUtil.uploadFile(filename,file.getInputStream());
        file.transferTo(new File("D:\\桌面\\files\\"+filename));
        return  Result.success(url);
    }
}
